package com.cbgolf.oa.activity.statistics;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.bill.BillListActivity;
import com.cbgolf.oa.base.BaseActivity;
import com.cbgolf.oa.entity.ChartBean;
import com.cbgolf.oa.entity.StatisticsBean;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.model.StatisticsModelImpl;
import com.cbgolf.oa.presenter.IStatisticsPresenter;
import com.cbgolf.oa.util.ClassUtil;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.util.ErrorUtil;
import com.cbgolf.oa.views.StatisticsView;

/**
 * @author Created by lq on 2017/9/14.
 */

public class StatisticsActivity extends BaseActivity implements
    IStatisticsPresenter {


  private StatisticsView view;
  private StatisticsModelImpl model;


  /**
   * type
   */
  private int mType;


  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.a_business_statistics);
  }

  @Override
  protected void findViews() {
    mType = DataUtil.getIntExtra(getIntent(), DataManager.KEY_TYPE, 0);
    view = new StatisticsView(this, this, mType);
    model = new StatisticsModelImpl(this);
    view.setViewInfo();
  }

  @Override
  protected void loadData() {
    model.getCurData(mType);
  }

  @Override
  public void showProgress() {
    view.showLoading();
  }

  @Override
  public void stopProgress() {
    view.stopLoading();
  }

  @Override
  public void getDataFail(String msg) {
    view.showError(msg);
  }


  @Override
  public void getDataSuccess(Object obj) {
    ChartBean bean = (ChartBean) obj;
    if (null == bean) {
      view.showError(ErrorUtil.NODATA);
      return;
    }
    view.setNumDatas(bean);
    view.setChartData(bean);
  }

  @Override
  public void reset() {
    view.reset();
  }

  @Override
  public void getPointSuccess(Object obj) {
    view.setPointData(obj);
  }

  @Override
  public void getPointFail() {
    view.setPointFail();
  }

  @Override
  public void getPointList() {
    model.getPointList();
  }

  @Override
  public void getFilterData(int dateType, int dataChooseType) {
    model.setFilterDateViews(dateType, dataChooseType);
  }

  @Override
  public void getLast(int dateType, int dataChooseType) {
    model.getLast(dateType, dataChooseType);
  }

  @Override
  public void getNext(int dateType, int dataChooseType) {
    model.getNext(dateType, dataChooseType);

  }

  @Override
  public void getChooseTypeData(int dateType, int dataChooseType) {
    model.getChooseTypeData(dateType, dataChooseType);
  }

  @Override
  public void setPoint(String code) {
    model.setPoint(code);
  }

  @Override
  public void getBussinessData() {
    model.getData();
  }

  @Override
  public void getBillData() {
    model.getData();
  }

  @Override
  public void ClickShowOrder() {
    mStartActivity(BillListActivity.class);
  }

  @Override
  public void showDetails(StatisticsBean data) {
    ClassUtil.startActivity(context, new Intent(context, ListStatisticsActivity.class)
        .putExtra(DataManager.KEY_TYPE, mType)
        .putExtra(DataManager.KEY_DATA, data));
  }

  @Override
  public void setDate(String date) {
    view.setDate(date);
  }

  @Override
  public void setNextTvLive(boolean b) {
    view.setNextTvLive(b);
  }

  @Override
  public void setFilterViews(int type) {
    view.setFilterViews(type);
  }

  @Override
  public String getActivityTitle() {
    return DataUtil.getCourseName();
  }

  @Override
  public void back() {
    finish();
  }

  @Override
  public void getDataFail(String msg, int code) {

  }
}

